<template>
  <!-- 附件类型文件上传列表 -->
  <view class="file_list_comp">
    <view class="item" v-for="(item, index) in fileList" :key="index">
      <view class="icon_box"><image class="icon" src="/static/img/resource/file1.svg" mode="aspectFill"></image></view>
      <view class="info_box">
        <view class="title text_hidden_1">{{ item.name }}</view>
        <view class="size">{{ renderSize(item.size) }}</view>
      </view>
      <view class="del" @click="remove(index)" v-if="showClose">删除</view>
      <view class="del" @click="download(item)" v-if="!showClose">下载</view>
    </view>
  </view>
</template>

<script>
import { renderSize } from '@/utils/utils.js';
export default {
  props: {
    fileList: {
      type: Array,
      default: () => []
    },
    showClose: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      renderSize: this.$utils.renderSize
    };
  },
  computed: {},
  created() {},
  methods: {
    download(item){
      window.location.href = item.url
    },
    remove(index) {
      uni.showModal({
        content: '确定移除该文件吗？',
        success: res => {
          if (res.confirm) {
            this.$emit('remove', index);
          }
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.file_list_comp {
  .item {
    position: relative;
    margin-top: 40rpx;
    .icon_box {
      display: inline-block;
      .icon {
        width: 76rpx;
        height: 76rpx;
      }
    }
    .info_box {
      vertical-align: top;
      display: inline-block;
      // margin-left: 24rpx;
      .title {
        width: 500rpx;
        font-size: 28rpx;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 40rpx;
      }
      .size {
        font-size: 24rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #777777;
        line-height: 34rpx;
      }
    }
    .del {
      position: absolute;
      right: 4rpx;
      top: 18rpx;
      font-size: 24rpx;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #c40000;
      line-height: 34rpx;
    }
  }
}
</style>
